package com.itheima.sh.c_demo;

import java.util.ArrayList;

public class UserTest {

    public static ArrayList<User> getUser(ArrayList<User> users){
        ArrayList<User> newlist = new ArrayList<>();
        for (int i = 0; i < users.size(); i++) {
            User user = users.get(i);
            String name = user.getName();
            int age = user.getAge();
            String sex = user.getSex();
            if (age>=18&&sex.equals("男")){
                newlist.add(user);
            }
        }
        return newlist;
    }
    public static void main(String[] args) {
        User user = new User("张三",20,"男");
        User user1 = new User("大鹏",28,"男");
        User user2 = new User("柳岩",25,"女");
        User user3 = new User("袁姗姗",20,"女");
        User user4 = new User("B哥",20,"男");
        ArrayList<User> list = new ArrayList<>();
        list.add(user);
        list.add(user1);
        list.add(user2);
        list.add(user3);
        list.add(user4);

        ArrayList<User> newlist = getUser(list);
        for (int i = 0; i < newlist.size(); i++) {
            User user5 = newlist.get(i);
            String name = user5.getName();
            int age = user5.getAge();
            String sex = user5.getSex();
            System.out.println(name+"--"+age+"--"+sex);
        }




    }

    }

